import React from 'react'
import { reqGetStuById } from '../../api/student'
import { Form, useLoaderData } from 'react-router-dom'
export const loader=async ({params})=>{
  
const res=await reqGetStuById(params.id)

return res
}
function Student() {
  const { data: student, meta } =useLoaderData()
    return (
        <div>
            <p>学生信息</p>
            <ul>
                <li>
                姓名：<span>{student.attributes.name}</span>
                </li>
                <li>
                性别：<span>{student.attributes.gender}</span>
                </li>
                <li>
                年龄: <span>{student.attributes.age}</span>
                </li>
            </ul>
           {/* 对应路由 student/：id/destory*/}
           {/* 点击该按钮，会将post请求发送到路由对应的action中处理 */}
          <Form method='post' action='destory'>
            <button type='submit'> 删除 </button>
          </Form>
           

        </div>
    )
}

export default Student